package com;

import com.fz.entity.Book;
import org.junit.Test;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * Created by webrx on 2017-09-07.
 */
public class Demo {
    @Test
    public void aa(){
        //BeanFactory f = new ClassPathXmlApplicationContext("applicationContext.xml");
        ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");

        Book bk5 = ctx.getBean("/bk5",Book.class);
        System.out.println(bk5.getUser().getName());

        for(Integer i : bk5.getList()){
            System.out.println(i);
        }

        ctx.close();

    }



    @Test
    public void tt() {
        BeanFactory f = new ClassPathXmlApplicationContext("applicationContext.xml");
//        Date d1 = f.getBean(Date.class);
//        Date d2 = f.getBean("d", Date.class);
//        System.out.println(d1 == d2);
//        System.out.println(d1.toLocaleString());
//        System.out.println(d2.toLocaleString());

        //Book b = f.getBean(Book.class);
        //System.out.println(b.getName());

//        Book b1 = f.getBean("book",Book.class);
//        System.out.println(b1.getId());
//        System.out.println(b1.getName());
//        Book b2 = f.getBean("bk2",Book.class);
//        System.out.println(b2.getId());
//        System.out.println(b2.getName());

        Book b1 = f.getBean("/bk3",Book.class);
        Book b2 = f.getBean("/bk3",Book.class);
        Book b3 = f.getBean("/bk3",Book.class);
        System.out.println(b1==b2);
        System.out.println(b1==b3);
        System.out.println(b2==b3);

        System.out.println(b1.getId());
        System.out.println(b2.getName());

        System.out.println(b3.getAddress().length);
        for(String addr : b3.getAddress()){
            System.out.println(addr);
        }


    }
}
